<%-- 
    Document   : connectMySQL
    Created on : Apr 15, 2011, 2:28:25 PM
    Author     : NguyenThuan
--%>
<%--
    Document   : index
    Created on : Apr 11, 2011, 10:55:24 AM
    Author     : NguyenThuan
--%>

<%@page import="java.sql.*"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
                    String driver = "org.gjt.mm.mysql.Driver";
                    Class.forName(driver).newInstance();

                    Connection con = null;
                    ResultSet rst = null;
                    Statement stmt = null;
                    String sql = null;

                    try {
                        String url = "jdbc:mysql://localhost:3306/books?user=root&password=123456789";
                        con = DriverManager.getConnection(url);
                        stmt = con.createStatement();
                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
                    sql = "select * from books_details";
                    rst = stmt.executeQuery(sql);
        %>
        <table border="1px">
            <tr>
                <th>STT</th>
                <th>Tên sách</th>
                <th>Tên tác giả</th>
            </tr>
            <%
                        int no = 1;
                        while (rst.next()) {
            %>

            <tr>
                <td><%=no%></td>
                <td><%=rst.getString("book_name")%></td>
                <td><%=rst.getString("author")%></td>
            </tr>
            <%
                            no++;
                        }
                        rst.close();
                        stmt.close();
                        con.close();
            %>
        </table>
    </body>
</html>
